﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Communications.Configuration
{
    /// <summary>
    /// 
    /// </summary>
    /// <seealso cref="System.Configuration.ConfigurationElement" />
    public class EmailSettings : ConfigurationElement
    {
        /// <summary>
        /// Gets or sets from.
        /// </summary>
        /// <value>
        /// From.
        /// </value>
        [ConfigurationProperty("from", IsRequired = true, IsKey = false)]
        public string From
        {
            get { return (string)this["from"]; }
            set { this["from"] = value; }
        }

        /// <summary>
        /// Gets to.
        /// </summary>
        /// <value>
        /// To.
        /// </value>
        [ConfigurationProperty("to", IsDefaultCollection = false)]
        [ConfigurationCollection(typeof(EmailItem), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
        public EmailsCollection To
        {
            get { return (EmailsCollection)base["to"]; }
        }

        /// <summary>
        /// </summary>
        /// <value>
        /// The cc.
        /// </value>
        [ConfigurationProperty("cc", IsDefaultCollection = false)]
        [ConfigurationCollection(typeof(EmailItem), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
        public EmailsCollection Cc
        {
            get { return (EmailsCollection)base["cc"]; }
        }

        /// <summary>
        /// Gets the address to send disposition notification email...
        /// </summary>
        /// <value>
        /// The disposition notification to.
        /// </value>
        //[ConfigurationProperty("dispositionNotificationTo", IsRequired = false, IsKey = false)]
        //public string DispositionNotificationTo
        //{
        //    get { return (string)this["dispositionNotificationTo"]; }
        //    set { this["dispositionNotificationTo"] = value; }
        //}

        [ConfigurationProperty("emailDeliverySettings", IsRequired = false, IsKey = false)]
        public EmailDeliverySettings EmailDeliverySettings
        {
            get { return (EmailDeliverySettings)this["emailDeliverySettings"]; }
            set { this["emailDeliverySettings"] = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EmailSettings"/> class.
        /// </summary>
        public EmailSettings()
        {
        }

        /// <summary>
        /// To the addresses.
        /// </summary>
        /// <returns></returns>
        public List<string> ToAddresses()
        {
            List<string> retValue = null;

            if ((this.To != null) && (this.To.Count > 0))
            {
                retValue = new List<string>();

                foreach (EmailItem item in this.To)
                {
                    retValue.Add(item.Email);
                }
            }
            return retValue;
        }

        /// <summary>
        /// Ccs the addresses.
        /// </summary>
        /// <returns></returns>
        public List<string> CcAddresses()
        {
            List<string> retValue = null;

            if ((this.Cc != null) && (this.Cc.Count > 0))
            {
                retValue = new List<string>();
                foreach (EmailItem item in this.Cc)
                {
                    retValue.Add(item.Email);
                }
            }

            return retValue;
        }
    }
}
